﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XEvents.Library
{
    internal class SqlCommandStrings
    {
        internal static string MetaData = @"select dm_xe_packages.* 
from sys.dm_xe_packages
where (dm_xe_packages.capabilities is null or dm_xe_packages.capabilities <> 1);

select dm_xe_objects.* 
from sys.dm_xe_objects
join sys.dm_xe_packages on dm_xe_objects.package_guid = dm_xe_packages.guid
where (dm_xe_packages.capabilities is null or dm_xe_packages.capabilities <> 1)
order by object_type desc;

select dm_xe_object_columns.* 
from sys.dm_xe_object_columns
join sys.dm_xe_packages on dm_xe_object_columns.object_package_guid = dm_xe_packages.guid
where (dm_xe_packages.capabilities is null or dm_xe_packages.capabilities <> 1);

select dm_xe_map_values.*
from sys.dm_xe_map_values
join sys.dm_xe_packages on dm_xe_map_values.object_package_guid = dm_xe_packages.guid
where (dm_xe_packages.capabilities is null or dm_xe_packages.capabilities <> 1);
";

        internal static string SessionDefinitions = @"select * from sys.server_event_sessions;
select * from sys.server_event_session_actions;
select * from sys.server_event_session_events;
select * from sys.server_event_session_fields;
select * from sys.server_event_session_targets;
";
        internal static string RunningSessions = @"select * from sys.dm_xe_sessions;
--select * from sys.dm_xe_session_event_actions;
--select * from sys.dm_xe_session_events;
--select * from sys.dm_xe_session_object_columns;
--select * from sys.dm_xe_session_targets;
";

        /*
        internal static string SessionTargetWatcher = @"select dm_xe_session_targets.* 
from sys.dm_xe_sessions
join sys.dm_xe_session_targets on dm_xe_sessions.address = dm_xe_session_targets.event_session_address
where dm_xe_sessions.name = @sessionname
  and dm_xe_session_targets.target_name = @targetname;
";
        */

        internal static string TargetData = @"select dm_xe_session_targets.target_data as xml
from sys.dm_xe_sessions
join sys.dm_xe_session_targets on dm_xe_sessions.address = dm_xe_session_targets.event_session_address
where dm_xe_sessions.name = '{0}'
  and dm_xe_session_targets.target_name = '{1}'";

        /// <summary>
        /// ALTER EVENT SESSION STATE Sql String
        /// </summary>
        internal static readonly string SessionStateSQL = "ALTER EVENT SESSION [{0}] ON SERVER STATE = {1}";

        /// <summary>
        /// CREATE EVENT SESSION Base
        /// </summary>
        internal static readonly string ScriptCreateBase = @"CREATE EVENT SESSION [{0}]
ON SERVER";

        /// <summary>
        /// DROP EVENT SESSION Base
        /// </summary>
        internal static readonly string ScriptDropBase = @"IF EXISTS(SELECT * FROM sys.server_event_sessions WHERE name='{0}')
    DROP EVENT SESSION [{0}] ON SERVER;
";
        /// <summary>
        /// ALTER EVENT SESSION Base
        /// </summary>
        internal static readonly string ScriptAlterEventSessionBase = @"ALTER EVENT SESSION [{0}] 
ON SERVER
";
        internal static readonly string ScriptSessionOptionsBase = @"WITH (MAX_MEMORY = {0}KB, EVENT_RETENTION_MODE = {1}, MAX_DISPATCH_LATENCY = {2} SECONDS, MAX_EVENT_SIZE = {3}KB, MEMORY_PARTITION_MODE = {4}, TRACK_CAUSALITY = {5}, STARTUP_STATE = {6})";

        internal static readonly string FileTargetData = @"select *
from sys.fn_xe_file_target_read_file ('{0}', '{1}', null, null)";


    }
}
